package com.qf.service.impl;

import com.qf.dao.AccountDao;
import com.qf.pojo.Account;
import com.qf.service.AccountService;
import com.qf.test.TestDao;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.service.impl
 * @Description:
 * @Date 2022/9/28 15:59
 */

@Component("accountService")
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true,rollbackFor = Exception.class)
public class AccountServiceImpl implements AccountService {

//    @Autowired
//    @Qualifier("testDaoImpl2")
//    TestDao testDao

//    @Autowired
//    TestDao testDao;

    @Autowired
    TestDao testDaoImpl1;

    @Autowired
    AccountDao accountDao;

//    public void setAccountDao(AccountDao accountDao) {
//        this.accountDao = accountDao;
//    }


    @Override
    @Transactional(propagation = Propagation.REQUIRED,readOnly = false,rollbackFor = Exception.class)
    public void trans(String name, String name1, double money) {
        Account accountFrom = accountDao.selectByName(name);
        Account accountTo = accountDao.selectByName(name1);

        accountFrom.setMoney(accountFrom.getMoney()-money);
        accountTo.setMoney(accountTo.getMoney()+money);

        accountDao.update(accountFrom);
//        System.out.println(1/0);
        accountDao.update(accountTo);
    }


}
